package com.bdqn.ch07.mapper.impl;

import com.bdqn.ch07.mapper.SysUserMapper;
import com.bdqn.ch07.pojo.Supplier;
import com.bdqn.ch07.pojo.SysUser;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.Collections;
import java.util.List;

/**
 * SysUserMapperImpl
 *
 * @aurhor Administrator  whs
 * @since 2024/7/19
 */
public class SysUserMapperImpl extends SqlSessionDaoSupport implements SysUserMapper {

    /**
     *  通过 SqlSessionTemplate 操作数据库
     */

    private SqlSessionTemplate sqlSession;


    /**
     * 查询用户列表
     * @param sysUser
     * @return
     */
    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser) {

        System.out.println(sqlSession);
      // return sqlSession.selectList("com.bdqn.ch07.mapper.SysUserMapper.selectSysUserList",sysUser);

        return sqlSession.getMapper(SysUserMapper.class).selectSysUserList(sysUser);

        // 使用 SqlSessionDaoSupport 简化代码
     // return this.getSqlSession().selectList("com.bdqn.ch07.mapper.SysUserMapper.selectSysUserList", sysUser);

    }

    /**
     * 添加用户信息
     *
     * @param sysUser
     * @return
     */
    @Override
    public int add(SysUser sysUser) {
        return this.getSqlSession().insert("com.bdqn.ch07.mapper.SysUserMapper.add", sysUser);
    }

    /**
     * 查询全部供货商
     *
     * @return
     */
    @Override
    public List<Supplier> selectAllSupplier() {
        return this.getSqlSession().getMapper(SysUserMapper.class).selectAllSupplier();
    }

    /**
     * ch07 实战4
     * 根据供货商ID进行删除
     *
     * @param id
     * @return
     */
    @Override
    public int deleteIdSupplier(int id) {
        return sqlSession.getMapper(SysUserMapper.class).deleteIdSupplier(id);
    }

    /**
     * ch07 实战4
     * 根据供货商id 修改供货商信息
     *
     * @param supplier
     * @return
     */
    @Override
    public int updateSupplierId(Supplier supplier) {
        return sqlSession.getMapper(SysUserMapper.class).updateSupplierId(supplier);
    }


    public SqlSessionTemplate getSqlSession() {
        return sqlSession;
    }

    public void setSqlSession(SqlSessionTemplate sqlSession) {
        this.sqlSession = sqlSession;
    }



}
